Skip to content

no-issue: disable tests conditionally when binary is not present#1191

Open
ricardozanini wants to merge 4 commits intoserverlessworkflow:mainfrom
ricardozanini:check-python
Open

no-issue: disable tests conditionally when binary is not present#1191
ricardozanini wants to merge 4 commits intoserverlessworkflow:mainfrom
ricardozanini:check-python

Conversation

@ricardozanini
Copy link
Member

Many thanks for submitting your Pull Request ❤️!

What this PR does / why we need it:
Sometimes, a local machine environment might not have python or protoc installed to run "unit" tests. In my opinion, these tests should be ITs and be on a specific profile.

However, if we want to run as unit tests and they depend on the environment where they're running, we disable the test if needed.

Special notes for reviewers:
mvn clean install now runs smoothly if python or grpc are not available.

Additional information (if needed):

Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a JUnit 5 annotation/extension to conditionally disable tests when required external binaries (e.g., protoc, python) are not available on the executing machine, improving mvn clean install reliability across environments.

Changes:

  • Introduce @DisabledIfBinaryUnavailable plus BinaryCheckCondition JUnit 5 ExecutionCondition.
  • Apply the new annotation to gRPC tests requiring protoc.
  • Apply the new annotation to the parameterized custom function test requiring python.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
impl/test/src/test/java/io/serverlessworkflow/impl/test/junit/DisabledIfBinaryUnavailable.java New annotation to register the binary-check execution condition.
impl/test/src/test/java/io/serverlessworkflow/impl/test/junit/BinaryCheckCondition.java New JUnit 5 ExecutionCondition that runs a command to determine binary availability.
impl/test/src/test/java/io/serverlessworkflow/impl/test/grpc/GrpcUnaryTest.java Disable test class when protoc is unavailable.
impl/test/src/test/java/io/serverlessworkflow/impl/test/grpc/GrpcUnaryArgsExprTest.java Disable test class when protoc is unavailable.
impl/test/src/test/java/io/serverlessworkflow/impl/test/grpc/GrpcServerStreamingTest.java Disable test class when protoc is unavailable.
impl/test/src/test/java/io/serverlessworkflow/impl/test/grpc/GrpcClientStreamingTest.java Disable test class when protoc is unavailable.
impl/test/src/test/java/io/serverlessworkflow/impl/test/grpc/GrpcBiDirectionalStreamingTest.java Disable test class when protoc is unavailable.
impl/test/src/test/java/io/serverlessworkflow/impl/test/CustomFunctionTest.java Disable the python-dependent parameterized test when python is unavailable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
Comment on lines +33 to +50
try {
Process process =
new ProcessBuilder(command)
.redirectErrorStream(true)
.redirectOutput(ProcessBuilder.Redirect.DISCARD)
.start();
boolean finished = process.waitFor(2, TimeUnit.SECONDS);
if (finished) {
return process.exitValue() == 0;
}
process.destroyForcibly();
return false;
} catch (IOException | InterruptedException e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
return false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try {
Process process =
new ProcessBuilder(command)
.redirectErrorStream(true)
.redirectOutput(ProcessBuilder.Redirect.DISCARD)
.start();
boolean finished = process.waitFor(2, TimeUnit.SECONDS);
if (finished) {
return process.exitValue() == 0;
}
process.destroyForcibly();
return false;
} catch (IOException | InterruptedException e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
return false;
}
ProcessBuilder processBuilder =
new ProcessBuilder(command)
.redirectErrorStream(true)
.redirectOutput(ProcessBuilder.Redirect.DISCARD);
Process process = null;
try {
process = process.start();
return process.waitFor(2, TimeUnit.SECONDS) && process.exitValue() == 0;
} catch (IOException e) {
// return default value
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
finally {
if (process != null) {
process.destroyForcibly();
}
}
return false;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to format this, but the idea is always destroy the process (with current implementation if it is not destroyed if something goes wrong), do not wrap process builder within the finally block and return false except when there is a process to query about.
And also avoid and unneeded instanceof by using two catch blocks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another alternative can be

Suggested change
try {
Process process =
new ProcessBuilder(command)
.redirectErrorStream(true)
.redirectOutput(ProcessBuilder.Redirect.DISCARD)
.start();
boolean finished = process.waitFor(2, TimeUnit.SECONDS);
if (finished) {
return process.exitValue() == 0;
}
process.destroyForcibly();
return false;
} catch (IOException | InterruptedException e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
return false;
}
Process process;
try {
process = new ProcessBuilder(command)
.redirectErrorStream(true)
.redirectOutput(ProcessBuilder.Redirect.DISCARD).start();
} catch (IOException e) {
return false;
}
try {
return process.waitFor(2, TimeUnit.SECONDS) && process.exitValue() == 0;
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
finally {
process.destroyForcibly();
}

Comment on lines +35 to +43
annotation -> {
if (isProtocAvailable()) {
return ConditionEvaluationResult.enabled(
"Protoc is available for the current platform.");
} else {
return ConditionEvaluationResult.disabled(
"Test disabled: Protoc not currently available not found.");
}
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
annotation -> {
if (isProtocAvailable()) {
return ConditionEvaluationResult.enabled(
"Protoc is available for the current platform.");
} else {
return ConditionEvaluationResult.disabled(
"Test disabled: Protoc not currently available not found.");
}
})
annotation ->
isProtocAvailable() ? ConditionEvaluationResult.enabled(
"Protoc is available for the current platform.") : ConditionEvaluationResult.disabled(
"Test disabled: Protoc not currently available not found."))


public class ProtocCheckCondition implements ExecutionCondition {

private static final AtomicReference<Boolean> protocAvailable = new AtomicReference<>(null);
Copy link
Collaborator

@fjtirado fjtirado Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static final AtomicReference<Boolean> protocAvailable = new AtomicReference<>(null);
private static boolean protocAvailable;
static {
try {
protocAvailable = Protoc.runProtoc(new String[] {"--version"}) == 0;
} catch (Exception e) {
// ignore
}
if (!protocAvailable) {
protoCAvailable= isBinaryAvailable("protoc", "--version");
}
}

Comment on lines +48 to +64
Boolean cached = protocAvailable.get();
if (cached != null) {
return cached;
}

boolean found = false;
try {
if (Protoc.runProtoc(new String[] {"--version"}) == 0) found = true;
} catch (Exception e) {
// ignore
}

if (!found) found = isBinaryAvailable("protoc", "--version");

protocAvailable.compareAndSet(null, found);

return protocAvailable.get();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Boolean cached = protocAvailable.get();
if (cached != null) {
return cached;
}
boolean found = false;
try {
if (Protoc.runProtoc(new String[] {"--version"}) == 0) found = true;
} catch (Exception e) {
// ignore
}
if (!found) found = isBinaryAvailable("protoc", "--version");
protocAvailable.compareAndSet(null, found);
return protocAvailable.get();
return protocAvailable;

Comment on lines +35 to +41
annotation -> {
if (isBinaryAvailable("python", "--version")) {
return ConditionEvaluationResult.enabled("Python is available.");
} else {
return ConditionEvaluationResult.disabled("Test disabled: Python not found.");
}
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
annotation -> {
if (isBinaryAvailable("python", "--version")) {
return ConditionEvaluationResult.enabled("Python is available.");
} else {
return ConditionEvaluationResult.disabled("Test disabled: Python not found.");
}
})
annotation -> {
isBinaryAvailable("python", "--version") ?
ConditionEvaluationResult.enabled("Python is available.") :
ConditionEvaluationResult.disabled("Test disabled: Python not found."))

Copy link
Collaborator

@fjtirado fjtirado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.
I have some non trivial comments regarding implementation, though

@fjtirado
Copy link
Collaborator

fjtirado commented Mar 2, 2026

@ricardozanini I just realized that, if protoc binary is not in classpath, it will be extracted from the jar dependency, so for grpc I do not think the check is needed (what Im trying to say if that the test will work in systems, like mine, where protoc is not installed, do not need to disable it, because isProtoCAvailable will always be true once the protoc dependency is there)
For Python, your rationale is good, so lets remove the protoc part and keep the python one of this PR

See https://github.com/os72/protoc-jar/blob/master/src/main/java/com/github/os72/protocjar/Protoc.java#L189-L230. In practise, something will be really screwed up if isProtoCAvailable were false, and probably in that case we should fail CI rather than go on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants